<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$this->model('member')->checklogin();
$shopset=$this->plugin_setting('shopset');
if($_RQ['op']=='main'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('配送单不存在，请重新选择订单','error');
	}	
	$item=pdo_get('jy_peiorder_sendlog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$work_weekarray=array('日','一','二','三','四','五','六');
	$item['goods']=json_decode($item['goods'],true);
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['is_addtitle']=$item['is_add']?'获得':'消费';
			if($item['sendtype']!=2){
				$item['statustitle']=$this->send_status[$item['status']];
			}else{
				$item['statustitle']=$this->send2_status[$item['status']];
			}
			$item['ordersn']=pdo_getcolumn('jy_weishop_order',array('id'=>$item['order_id']),'ordersn');
			$week = date('w', strtotime($item['day']));
			$item['week'] = '星期'.$work_weekarray[$week];
			$order=pdo_get('jy_weishop_order',array('id'=>$item['order_id']),array('ordersn','price','merchid','address','addressid'));
			$item['get_money']=$this->model('model')->get_peifee($order,$item['mid'],$item['goods']);
			//用户地址
			$order['address']=json_decode($order['address'],true);
			if($order['address'] && ($order['address']['name'] || $order['address']['realname'])){
				$address=$order['address'];
			}else{
				$address=pdo_get('core_address',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['addressid']));
			}
			if(!is_array($address['pcd'])){
				$address['pcd']=json_decode($address['pcd'],true);
			}
	$item['order_out']=$address;
	if($item['mid']){
				$item['peimember']=pdo_get('jy_peiorder_member',array('mid'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('title','mobile','level_id'));
				$item['peimember']['level']=pdo_getcolumn('jy_peiorder_level',array('id'=>$item['peimember']['level_id'],'uniacid'=>$_SESSION['uniacid']),'title');
				$item['peimember']['level']=$item['peimember']['level']?:'普通等级';
	}
	$return['item']=$item;
	$return['post']=array('star'=>5,'fuwustar'=>5,'sendstar'=>5,'merchid'=>$item['merchid'],'peisong_id'=>$item['mid'],'orderid'=>$item['order_id'],'log_id'=>$item['id']);
	set_html('title','配送评价');
	exi($return);
}

if($_RQ['op']=='submit'){
	$postdata=get_postdata();
	$data=array(
		'content'=>$postdata['content'],
		'images'=>ijson_encode($postdata['images']),
		'star'=>intval($postdata['star']),
		'sendstar'=>intval($postdata['sendstar']),
		'fuwustar'=>intval($postdata['fuwustar']),
	);
	$comment_id=$this->pdo_getcolumn('pingjia',array('orderid'=>intval($postdata['orderid']),'log_id'=>intval($postdata['log_id'])),'id');
	if($comment_id){
		exi('该评价已生效显示，不可修改！','error','goback');
		$this->pdo_update('pingjia',$data,array('id'=>$comment_id));
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'orderid'=>intval($postdata['orderid']),
			'log_id'=>intval($postdata['log_id']),
			'peisong_id'=>intval($postdata['peisong_id']),
			'merchid'=>intval($postdata['merchid']),
			'createtime'=>TIMESTAMP,
		);
		$data=array_merge($insert,$data);
		$this->pdo_insert('pingjia',$data);
		$this->pdo_update('sendlog',array('ispingjia'=>1),array('id'=>intval($postdata['log_id'])));
		if($data['star']==5){
			$this->model('member')->pingji_hao($data['log_id']);
		}
		if($data['star']<=1){
			$this->model('member')->pingji_cha($data['log_id']);
		}
	}
	exi('评价成功！','','goback');
}
?>